package com.weasel.weixin.commons.menu;

import com.google.common.collect.ImmutableMap;
import com.weasel.http.HttpClientSecretary;
import com.weasel.weixin.commons.CommonRequest;
import com.weasel.weixin.commons.config.CommonConfig;
import com.weasel.weixin.commons.menu.bean.Menu;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

/**菜单请求类
 * Created by Dylan on 2015/10/8.
 */
public abstract class MenuRequest extends CommonRequest {


    public MenuRequest(CommonConfig config) {
        super(config);
    }

    public MenuResponse create(Menu menu) throws ExecutionException, IOException {

        MenuResponse menuResponse = HttpClientSecretary.post()
                                                       .withURI(getBaseUrl(getCreateURL()))
                                                       .withParam(menu)
                                                       .doItWithJson(MenuResponse.class);
        return menuResponse;
    }

    public MenuResponse delete() throws ExecutionException, IOException {

        MenuResponse menuResponse = HttpClientSecretary.post()
                                                            .withURI(getBaseUrl(getDeleteURL()))
                                                            .doItWithJson(MenuResponse.class);
        return menuResponse;
    }

    public MenuResponse get() throws ExecutionException, IOException {

        MenuResponse menuResponse = HttpClientSecretary.get()
                                                        .withURI(getQueryURL())
                                                        .withParams(ImmutableMap.of("access_token", getAccessToken()))
                                                        .doItWithJson(MenuResponse.class);
        return menuResponse;
    }

    protected abstract String getCreateURL();

    protected abstract String getDeleteURL();

    protected abstract String getQueryURL();

}
